/*package com.wsjc.web.controller;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.wsjc.common.core.entity.ApiCommonResultVo;
import com.wsjc.manager.entity.WjHospital;

@RestController
@RequestMapping(value = "/pc/")
public class PcSoftWareController {

	private static Logger logger = LoggerFactory.getLogger(PcDataController.class);


	
	@InitBinder
	protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
		// 对于需要转换为Date类型的属性，使用DateEditor进行处理
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		CustomDateEditor editor = new CustomDateEditor(df, false);
		binder.registerCustomEditor(Date.class, editor);
	}

	*//**
	 * 1.1 Pc 软件验证 （方式 1 ） 请求方式 ：POST 参数 ：PartName 被监测单位名称 ， PartBussno 营业执照号 ，
	 * key 软件秘钥
	 * 
	 * @return 0 不成功--》空 , 1 成功--》 partID : 单位ID
	 *//*
	@RequestMapping(value = "softCheckWay1", method = RequestMethod.GET)
	public ApiCommonResultVo softCheckWay1(String PartName, String PartBussno, String Key) {

		try {
			logger.info("PC-1.1|软件验证 ");

			String city_id = PartName.substring(0, 6).toString();
			PartName = PartName.substring(6).toString();
			System.out.println(" 城市的ID ：" + city_id);

			Map<String, Object> paramsMap = new HashMap<String, Object>();
			paramsMap.put("PartName", PartName);
			paramsMap.put("PartBussno", PartBussno);
			paramsMap.put("t_hospital", Constants.T_HOSPITAL + city_id);

			WjHospital wjHospital = pcService.findHospitalByNameAndBussno(paramsMap);

			if (null == wjHospital) {
				logger.warn("PC-1.1|未检索到相关医院 params: PartName ->{}, PartBussno ->{}, Key ->{}", PartName, PartBussno,
						Key);
				return new ApiCommonResultVo(0, "参数错误", null);
			}
			if (wjHospital.getKey().equals(Key)) {
				return new ApiCommonResultVo(0, "验证成功", wjHospital.getId());
			} else {
				return new ApiCommonResultVo(-1, "秘钥key不正确", null);
			}

		} catch (Exception e) {
			logger.error("PC-1.1|error:{}", e);
			return new ApiCommonResultVo(-2, "系统异常", null);
		}
	}

	*//**
	 * Pc 软件验证 （方式 2 ） 请求方式 ：POST 参数 ：PartID : 单位ID ， key 软件秘钥
	 * 
	 * @return 0 不成功--》空 , 1 成功--》 partName : 单位名称
	 *//*
	@RequestMapping(value = "softCheckWay2", method = RequestMethod.GET)
	public ApiCommonResultVo softCheckWay2(String PartID, String Key) {
		
		logger.info("PC-1.2|软件验证  ");
		try {
			// 处理空格
			PartID = PartID.replace(" ", "");
			// 处理PartID 大小写
			PartID = HelpUtil.TreateHospitalID(PartID);
			String city_id = PartID.substring(0, 6).toString();
			String hospital_id = PartID.substring(6).toString();
			System.out.println(" Pc 软件验证 （方式  2 ）  获取到的  值 ：    " + Key);
			System.out.println(" 城市的ID ：" + city_id);
			Map<String, Object> paramsMap = new HashMap<String, Object>();
			paramsMap.put("hospital_id", hospital_id);
			paramsMap.put("t_hospital", Constants.T_HOSPITAL + city_id);
			System.out.println(" 参数  ：" + paramsMap);
			
			WjHospital wjHospital = pcService.findHospitalByNameAndBussno(paramsMap);
			if (null == wjHospital) {
				logger.warn("PC-1.1|未检索到相关医院 params: PartID ->{}, Key ->{}", PartID, Key);
				return new ApiCommonResultVo(0, "参数错误", null);
			}
			if (wjHospital.getKey().equals(Key)) {
				return new ApiCommonResultVo(0, "验证成功", wjHospital.getId());
			} else {
				return new ApiCommonResultVo(-1, "秘钥key不正确", null);
			}

		} catch (Exception e) {
			logger.error("PC-1.1|error:{}", e);
			return new ApiCommonResultVo(-2, "系统异常", null);
		}
	}

	
	*//**
	 * 5.1 软件上传
	 * 
	 * @return 0 不成功 , 1 成功
	 *//*
	@RequestMapping(value = "upSoft", method = RequestMethod.POST)
	public Map<String, Object> upSoft(String Key, String SoftName, String SoftVersion, String SoftInstruction,
			MultipartFile Soft, HttpSession session) {

		log.info("PC接口 :5.1 " + DateUtil.getTime());
		// 字符编码处理
		try {
			
			 * if(null != SoftName ){ SoftName = URLDecoder.decode(SoftName ,
			 * "GBK"); }
			 
			if (null != SoftInstruction) {
				SoftInstruction = SoftInstruction.replace("=", "");
				SoftInstruction = URLDecoder.decode(SoftInstruction, "GBK");
			}
		} catch (UnsupportedEncodingException e2) {
			log.info("捕获异常：" + DateUtil.getTime() + " " + e2.getMessage());
		}
		// 验证文件是否为空
		if (Soft.isEmpty()) {
			return MapModel.getMapModel("0", "", "请选择文件");
		}
		if (null == SoftName) {
			return MapModel.getMapModel("0", "", "软件名称不能为空");
		}

		String OssPath = "";
		String ID = UUIDUtil.getRandom32EndTimePK();
		String fileType = Soft.getOriginalFilename().indexOf(".") != -1 ? Soft.getOriginalFilename().substring(
				Soft.getOriginalFilename().lastIndexOf("."), Soft.getOriginalFilename().length()).toLowerCase() : null;
		if (fileType.equals(".exe")) {
			OssPath = Constants.UP_OSS_FILEPATH_EXE + SoftName + SoftVersion + fileType;
		} else if (fileType.equals(".apk")) {
			OssPath = Constants.UP_OSS_FILEPATH_APK + SoftName + SoftVersion + fileType;
		} else {
			return MapModel.getMapModel("0", "", "软件格式不对");
		}

		Ssoft s = new Ssoft();
		s.setId(ID);
		s.setKey(Key);
		s.setSoftname(SoftName);
		s.setSoftversion(SoftVersion);
		s.setSoftinstruction(SoftInstruction);
		s.setFiletype(fileType);
		s.setOssurl(Constants.ALIYUN_OSS_PATH + OssPath );
		s.setSource("甲方");
		pcService.addPcSoft(s);
		try {
			// 往数据库中更新app版本
			OSSFile.openBucketAndUpFile(Soft.getInputStream(), OssPath);
			// UploadUtil.delFile(Path);
		} catch (Exception e) {
			log.info("捕获异常：" + e.getMessage());
		}
		return MapModel.getMapModel("1", "上传成功", "");
	}

	*//**
	 * 5.2 获取最新软件信息
	 *//*
	@RequestMapping(value = "findSoft", method = RequestMethod.GET)
	public Map<String, Object> findSoft(String PartID, String Key, String SoftName) {
		log.info("PC接口 :5.2 " + DateUtil.getTime());
		// 字符编码处理
		
		 * try { if(null != SoftName ){ SoftName = URLDecoder.decode(SoftName ,
		 * "GBK"); } } catch (UnsupportedEncodingException e2) {
		 * log.info("捕获异常：" + DateUtil.getTime() + " " + e2.getMessage() ); }
		 
		// 处理空格
		PartID = PartID.replace(" ", "");
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		String city_id = "";
		String hospital_id = "";
		// 处理PartID 大小写
		try {
			PartID = HelpUtil.TreateHospitalID(PartID);
			// 验证秘钥
			city_id = PartID.substring(0, 6).toString();
			hospital_id = PartID.substring(6).toString();
		} catch (Exception e1) {
			log.info("捕获异常：" + DateUtil.getTime() + " " + e1.getMessage());
			return MapModel.getMapModel("0", "", "用户名异常");
		}
		paramsMap.put("hospital_id", hospital_id);
		paramsMap.put("t_hospital", Constants.T_HOSPITAL + city_id);
		Hospital hospital = null;
		try {
			hospital = pcService.findHospitalByID(paramsMap);
		} catch (Exception e) {
			log.info("捕获异常：" + DateUtil.getTime() + " " + e.getMessage());
			return MapModel.getMapModel("0", "", "正在建设中，请耐心等待！");
		}
		if (null == hospital) {
			return MapModel.getMapModel("0", "", "单位不存在");
		}
		if (!hospital.getHospital_key().equals(Key)) {
			return MapModel.getMapModel("0", "", "秘钥不正确");
		}
		if (null != hospital.getUse_expiry_date()) {
			if (new Date().getTime() > hospital.getUse_expiry_date().getTime()) {
				return MapModel.getMapModel("1", "", "有效期过期");
			}
		}

		Ssoft s = new Ssoft();
		s.setKey(Key);
		s.setSoftname(SoftName);
		Ssoft newSoft = pcService.findPcSoft(s);
		if (null == newSoft) {
			return MapModel.getMapModel("0", "", "没有该软件");
		}
		List<String> list = new ArrayList<String>();
		list.add(newSoft.getSoftversion());
		list.add(newSoft.getSoftinstruction());
		return MapModel.getMapModel("1", list, "");
	}

	*//**
	 * 5.3 软件下载 key 单位秘钥
	 *//*
	@RequestMapping(value = "downSoft", method = RequestMethod.GET)
	public Map<String, Object> downSoft(String PartID, String Key, String SoftName, HttpSession session,
			HttpServletResponse response) {
		log.info("PC接口 :5.3 " + DateUtil.getTime());
		// 字符编码处理
		
		 * try { if(null != SoftName ){ SoftName = URLDecoder.decode(SoftName ,
		 * "GBK"); } } catch (UnsupportedEncodingException e2) {
		 * log.info("捕获异常：" + DateUtil.getTime() + " " + e2.getMessage() ); }
		 
		// 处理空格
		PartID = PartID.replace(" ", "");
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		String city_id = "";
		String hospital_id = "";
		// 处理PartID 大小写
		try {
			PartID = HelpUtil.TreateHospitalID(PartID);
			// 验证秘钥
			city_id = PartID.substring(0, 6).toString();
			hospital_id = PartID.substring(6).toString();
		} catch (Exception e1) {
			log.info("捕获异常：" + DateUtil.getTime() + " " + e1.getMessage());
			return MapModel.getMapModel("0", "", "用户名异常");
		}
		paramsMap.put("hospital_id", hospital_id);
		paramsMap.put("t_hospital", Constants.T_HOSPITAL + city_id);
		Hospital hospital = null;
		try {
			hospital = pcService.findHospitalByID(paramsMap);
		} catch (Exception e) {
			log.info("捕获异常：" + DateUtil.getTime() + " " + e.getMessage());
			return MapModel.getMapModel("0", "", "正在建设中，请耐心等待！");
		}
		if (null == hospital) {
			return MapModel.getMapModel("0", "", "单位不存在");
		}
		if (!hospital.getHospital_key().equals(Key)) {
			return MapModel.getMapModel("0", "", "秘钥不正确");
		}
		if (null != hospital.getUse_expiry_date()) {
			if (new Date().getTime() > hospital.getUse_expiry_date().getTime()) {
				return MapModel.getMapModel("1", "", "有效期过期");
			}
		}

		if (null == SoftName) {
			return MapModel.getMapModel("0", "", "软件名称不能为空");
		}

		// 验证软件是否存在
		Ssoft s = new Ssoft();
		s.setKey(Key);
		s.setSoftname(SoftName);
		Ssoft newSoft = pcService.findPcSoft(s);
		if (null == newSoft) {
			return MapModel.getMapModel("0", "", "没有该软件");
		}

		String ossPath = "";
		if (newSoft.getFiletype().equals(".exe")) {
			ossPath = Constants.UP_OSS_FILEPATH_EXE + SoftName + newSoft.getSoftversion() + newSoft.getFiletype();
		} else {
			ossPath = Constants.UP_OSS_FILEPATH_APK + SoftName + newSoft.getSoftversion() + newSoft.getFiletype();
		}

		String FilePath = session.getServletContext().getRealPath(Constants.UPLOAD_APK_PATH) + "\\" + SoftName
				+ newSoft.getSoftversion() + newSoft.getFiletype();
		*//*************** Oss 下载文件 *****************//*
		try {
			OSSFile.DownFile(ossPath, FilePath);
		} catch (Exception e1) {
			System.out.println(" 下载失败---- ");
			log.info("捕获异常：" + DateUtil.getTime() + " " + e1.getMessage());
		}
		response.setCharacterEncoding("utf-8");
		response.setContentType("multipart/form-data");
		response.setHeader("Content-Disposition",
				"attachment;fileName=" + SoftName + newSoft.getSoftversion() + newSoft.getFiletype());
		byte[] dtb_type = null;
		try {
			InputStream inputStream = new FileInputStream(FilePath);
			OutputStream os = response.getOutputStream();
			dtb_type = new byte[1024 * 2];
			int length;
			while ((length = inputStream.read(dtb_type)) > 0) {
				os.write(dtb_type, 0, length);
			}
			inputStream.close();
		} catch (FileNotFoundException e) {
			UploadUtil.delFile(FilePath);
			log.info("捕获异常：" + DateUtil.getTime() + " " + e.getMessage());
		} catch (IOException e) {
			UploadUtil.delFile(FilePath);
			log.info("捕获异常：" + DateUtil.getTime() + " " + e.getMessage());
		}
		boolean fal = UploadUtil.delFile(FilePath);
		if (fal) {
			System.out.println("删除成功.........");
		} else {
			System.out.println("删除失败..................");
		}
		return null;
	}
	


	*//**
	 * 下载账单
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 *//*
	@RequestMapping("downChnBill")
	public ResponseEntity<byte[]> downChnBill(HttpServletRequest request) {
		String startDay = request.getParameter("startDate");
		if(startDay == null){
			throw new BizException("起始日期不能为空");
		}
		String endDay = request.getParameter("endDate");
		if(endDay == null){
			throw new BizException("终止日期不能为空");
		}
		String startDate = startDay.replace("-", "");
		String endDate = endDay.replace("-", "");
		String chnId = request.getParameter("chnid");
		String chnName = request.getParameter("chnName");
		String payType = request.getParameter("payType");

		StringBuilder sbContent = new StringBuilder();
		List<TBillProfitExt> list = chnBillDownLoadService.getChnBill(startDate, endDate, chnId, chnName, payType);
		if (list != null && list.size() > 0) {
			sbContent.append("渠道ID,渠道名称,支付类型,费率,商户交易总额,结算金额,开始日期,结束日期\r\n");
			for (TBillProfitExt billProfit : list) {
				if (billProfit != null) {
					String chnname = billProfit.getChnName();
					if(billProfit.getChnName() == null){
						chnname = "";
					}
					sbContent.append("`");
					sbContent.append(billProfit.getToUmid());
					sbContent.append(",`");
					sbContent.append(chnname);
					sbContent.append(",`");
					sbContent.append(billProfit.getPaytypeName());
					sbContent.append(",`");
					sbContent.append(billProfit.getFeeAmt());
					sbContent.append(",`");
					sbContent.append(billProfit.getBaseFee());
					sbContent.append(",`");
					sbContent.append(billProfit.getPayment());
					sbContent.append(",`");
					sbContent.append(billProfit.getStartDate());
					sbContent.append(",`");
					sbContent.append(billProfit.getEndDate());
					sbContent.append("\r\n");
				}
			}
		}
		if(Strings.isNullOrEmpty(chnId)){
			chnId = "";
		}
		String fileName = chnId + "(" + startDate + "-" + endDate + ")" + ".csv";
		HttpHeaders headers = new HttpHeaders();
		headers.setContentDispositionFormData("attachment", fileName);
		headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
		ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(
				sbContent.toString().getBytes(Charset.forName("GBK")), headers, HttpStatus.CREATED);
		return response;
	}
	
	
	
}
*/